<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>聊天室</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="https://cdn.jsdelivr.net/npm/sockjs-client@1.6.1/dist/sockjs.min.js"></script>
</head>
<body>
    <!-- 连接状态指示器 -->
    <div class="connection-status connecting" id="connectionStatus">
        <span class="loading"></span> 连接中...
    </div>
    
    <div class="chat-container">
        <!-- 侧边栏 -->
        <div class="sidebar">
            <div class="sidebar-header">
                <h2>💬 聊天室</h2>
                <div class="user-info">
                    <span>欢迎，</span>
                    <span id="currentUsername">用户</span>
                </div>
            </div>
            
            <div class="user-list">
                <h3>在线用户 (<span id="userCount">0</span>)</h3>
                <div id="userListContainer">
                    <!-- 用户列表将通过JavaScript动态生成 -->
                </div>
            </div>
        </div>
        
        <!-- 主聊天区域 -->
        <div class="main-chat">
            <div class="chat-header">
                <h2>群聊大厅</h2>
                <div class="chat-info">
                    <span>实时聊天 • </span>
                    <span id="onlineStatus">连接中...</span>
                </div>
            </div>
            
            <div class="messages-container" id="messagesContainer">
                <!-- 聊天消息将通过JavaScript动态生成 -->
                <div class="message system">
                    <div class="message-bubble">
                        <div class="message-content">欢迎来到聊天室！开始和大家聊天吧 🎉</div>
                    </div>
                </div>
            </div>
            
            <div class="input-container">
                <form class="input-form" id="messageForm">
                    <textarea 
                        id="messageInput" 
                        class="message-input" 
                        placeholder="输入消息..." 
                        rows="1"
                        maxlength="500"
                        disabled
                    ></textarea>
                    <button type="submit" class="send-btn" id="sendBtn" disabled>
                        发送
                    </button>
                </form>
            </div>
        </div>
    </div>
    
    <!-- 模态框：用户名输入 -->
    <div class="modal" id="usernameModal" style="display: none;">
        <div class="modal-content">
            <div class="modal-header">
                <h3>设置用户名</h3>
                <p>请输入您的用户名以开始聊天</p>
            </div>
            <form id="usernameForm">
                <div class="input-group">
                    <label for="modalUsername">用户名</label>
                    <input 
                        type="text" 
                        id="modalUsername" 
                        placeholder="请输入用户名" 
                        required 
                        maxlength="20"
                        autocomplete="off"
                    >
                </div>
                <div class="modal-actions">
                    <button type="submit" class="modal-btn primary">确认</button>
                    <button type="button" class="modal-btn secondary" onclick="window.location.href='/'">返回首页</button>
                </div>
            </form>
            <div class="error-message" id="modalErrorMessage" style="display: none;"></div>
        </div>
    </div>
    
    <style>
        /* 模态框样式 */
        .modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 2000;
        }
        
        .modal-content {
            background: white;
            border-radius: 12px;
            padding: 30px;
            width: 90%;
            max-width: 400px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
        }
        
        .modal-header {
            text-align: center;
            margin-bottom: 25px;
        }
        
        .modal-header h3 {
            color: #007bff;
            font-size: 1.5rem;
            margin-bottom: 8px;
        }
        
        .modal-header p {
            color: #6c757d;
            font-size: 0.9rem;
        }
        
        .modal-actions {
            display: flex;
            gap: 10px;
            margin-top: 20px;
        }
        
        .modal-btn {
            flex: 1;
            padding: 12px;
            border: none;
            border-radius: 8px;
            font-size: 0.9rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .modal-btn.primary {
            background: #007bff;
            color: white;
        }
        
        .modal-btn.primary:hover {
            background: #0056b3;
        }
        
        .modal-btn.secondary {
            background: #6c757d;
            color: white;
        }
        
        .modal-btn.secondary:hover {
            background: #545b62;
        }
        
        /* 隐藏滚动条但保持功能 */
        .messages-container {
            scrollbar-width: thin;
            scrollbar-color: #c1c1c1 #f1f1f1;
        }
        
        /* 消息输入框自动调整高度 */
        .message-input {
            overflow-y: hidden;
            resize: none;
        }
        
        /* 响应式调整 */
        @media (max-width: 768px) {
            .sidebar {
                position: fixed;
                top: 0;
                left: -280px;
                height: 100vh;
                z-index: 1000;
                transition: left 0.3s ease;
            }
            
            .sidebar.open {
                left: 0;
            }
            
            .main-chat {
                width: 100%;
            }
            
            .chat-header {
                position: relative;
            }
            
            .menu-toggle {
                position: absolute;
                left: 20px;
                top: 50%;
                transform: translateY(-50%);
                background: none;
                border: none;
                font-size: 1.2rem;
                cursor: pointer;
                color: #007bff;
            }
        }
    </style>
    
    <script src="js/chat.js"></script>
</body>
</html>